package com.qiudaozhang.jblog.frontend.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.qiudaozhang.jblog.article.service.ArticleService;
import com.qiudaozhang.jblog.article.service.CategoryService;
import com.qiudaozhang.jblog.article.service.TagService;
import com.qiudaozhang.jblog.model.Article;
import com.qiudaozhang.jblog.model.ArticleInfo;
import com.qiudaozhang.jblog.model.Category;
import com.qiudaozhang.jblog.model.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 邱道长
 * 2018/12/13 17:02
 * 前端入口
 */
@Controller
public class HomeController {

    @Reference(url = "${article.service.provider.url}", version = "${service.version}", group = "${dubbo.group}")
    private ArticleService articleService;
    
    @Reference(url = "${article.service.provider.url}", version = "${service.version}", group = "${dubbo.group}")
    private CategoryService categoryService;

    @Reference(url = "${article.service.provider.url}", version = "${service.version}", group = "${dubbo.group}")
    private TagService tagService;
    /**
     * 前端首页
     * @param model
     * @return
     */
    @RequestMapping("/")
    public String index(Model model){
        PageInfo<ArticleInfo> page = articleService.queryPageOrderByUpdateTimeDesc(1, 10);
        model.addAttribute("p",page);
        // 查询所有分类信息
        List<Category> categories = categoryService.selectAll();
        model.addAttribute("categories",categories);
        // 查询热门标签
        List<Tag> tags = tagService.selectAll();
        model.addAttribute("tags",tags);
        return "index";
    }


}
